<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>小广告</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #ad {
            position: fixed;
            background-color: red;
            width: 300px;
            height: 300px;
            right: 0;
            bottom: 0;
            display: none;
        }
    </style>
</head>
<body>

<div id="ad">
    <span>还有<span style="color: white" id="num">10</span>秒自动关闭广告</span>

</div>
</body>
<script>
    //第一步  要知道布局     小广告在右下角
    var ad = document.getElementById("ad");
    var span = document.getElementById("num");
    var count = Number(span.innerHTML);
    var timer;
    var timer2;


    ad.onclick = function(){
        ad.style.display = "none";
        window.open("https://www.baidu.com")

    }

 timer2= setTimeout(function () {
        ad.style.display = "block"; //让div显示
        //开始倒计时
        clearInterval(timer);
        timer = setInterval(function () {
            count--; //每隔一秒 然后count减少1
            span.innerHTML = count;  //把减少后的数值  重新显示到span
            if (count == 0) {
                ad.style.display = "none";
                clearInterval(timer);
            }
        }, 1000);

    }, 3000);
</script>
</html>